<template>
  <div class="equipmentManagement">
    <MetaSearchForm @on-search="tableSearch">
      <el-form ref="equipmentManagement_form" :model="searchData" label-width="105px">
        <el-form-item label="设备序列号" class="equipmentManagement_formItem">
          <el-input v-model="searchData.sernumber" placeholder="请输入设备序列号" clearable></el-input>
        </el-form-item>
        <el-form-item label="用户设备名称" class="equipmentManagement_formItem">
          <el-input v-model="searchData.equipmentname" placeholder="请输入用户设备名称" clearable></el-input>
        </el-form-item>
        <el-form-item label="设备名称" class="equipmentManagement_formItem">
          <el-input v-model="searchData.alias" placeholder="请输入设备名称" clearable></el-input>
        </el-form-item>
        <el-form-item label="主板编号" class="equipmentManagement_formItem">
          <el-input v-model="searchData.snid" placeholder="请输入主板编号" clearable></el-input>
        </el-form-item>
        <!-- <el-form-item label="设备状态" class="equipmentManagement_formItem">
          <el-select v-model="searchData.ontype" placeholder="请选择设备类型" clearable>
            <el-option
              v-for="item in equTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="客户" class="equipmentManagement_formItem">
          <el-select v-model="searchData.customerId" placeholder="请选择客户" clearable>
            <el-option
              v-for="item in customerList"
              :key="item.id"
              :label="item.customerName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </MetaSearchForm>
    <MetaPageTable
      ref="equipmentManagementTable"
      class="equipmentManagement_table"
      table-title="设备管理"
      :need-checkbox="false"
      :is-auto-req="false"
      :display-item="displayItem"
      :table-data="equTableData"
      :btn-group="btnGroup"
      :line-btn-group="lineBtnGroup"
      :is-manual-paging="true"
      @pageChange="pageChange"
      @btnClick="tableBtnClick"
      @lineBtnClick="tableInlineBtnClick"
    />
    <el-dialog
      v-if="tableChangeDialogFlag"
      :title="itemEditData.id && itemEditData.id !== '' ? '编辑设备' : '新建设备'"
      :visible.sync="tableChangeDialogFlag"
      width="80%"
      modal
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false">
      <el-form ref="equipmentEdit_form" :model="itemEditData" label-width="130px" :rules="editRules">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="设备序列号" prop="sernumber">
              <el-input v-model="itemEditData.sernumber" placeholder="请输入设备序列号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="主板编号" prop="snid">
              <el-input v-model="itemEditData.snid" placeholder="请输入主板编号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="用户设备名称" prop="equipmentname">
              <el-input v-model="itemEditData.equipmentname" placeholder="请输入用户设备名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备名称" prop="alias">
              <el-input v-model="itemEditData.alias" placeholder="请输入设备名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="设备型号">
              <el-select v-model="itemEditData.emid" placeholder="请选择设备型号" filterable class="equipTypeSelect">
                <el-option
                  v-for="item in equipmentModelList"
                  :key="item.id"
                  :label="item.equipmentModelName"
                  :value="item.id">
                  <span style="float: left">{{ item.equipmentModelName }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.equipmentModel }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备类型" prop="equipmentType">
              <el-select v-model="itemEditData.equipmentType" placeholder="请选择设备类型" clearable class="equipTypeSelect">
                <el-option label="浮标式设备" :value="1"></el-option>
                <el-option label="便携式设备" :value="2"></el-option>
                <el-option label="岸基式设备" :value="3"></el-option>
                <el-option label="管道式设备" :value="4"></el-option>
                <el-option label="潜入式设备" :value="5"></el-option>

              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="光栅编号">
              <el-input v-model="itemEditData.rasterNumber" placeholder="请输入光栅编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户">
              <el-select v-model="itemEditData.customerId" placeholder="请选择客户" filterable class="equipTypeSelect" clearable>
                <el-option
                  v-for="item in customerList"
                  :key="item.id"
                  :label="item.customerName"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="通讯模块型号">
              <!-- <el-input-number v-model="itemEditData.model" placeholder="请输入通讯模块型号"></el-input-number> -->
              <el-input v-model="itemEditData.model" placeholder="请输入通讯模块型号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="通讯模块编号">
              <el-input v-model="itemEditData.communicationCode" placeholder="请输入通讯模块编号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
         <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="设备版本">
              <el-input-number v-model="itemEditData.version" placeholder="请输入设备版本" :step="1" :min="0"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col v-if="!(itemEditData.id && itemEditData.id !== '')" :span="8">
            <el-form-item label="定标系数">
              <el-select v-model="itemEditData.dbxsType" placeholder="请选择定标系数" class="equipTypeSelect">
                <el-option label="白板系数" value="0"></el-option>
                <el-option label="灰板系数" value="1"></el-option>
                <el-option label="无系数" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="!(itemEditData.id && itemEditData.id !== '')" :span="8">
            <el-form-item label="暗电流参与计算">
              <el-switch v-model="itemEditData.adlType"
                active-value="1"
                inactive-value="0"
                active-color="#13ce66"
                inactive-color="#ff4949">
              </el-switch>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="算法">
          <el-select @change="aNameChange" v-model="itemEditData.aName"  placeholder="请选择算法" filterable class="equipTypeSelect">
            <el-option
              v-for="item in algorithmList"
              :key="item.id"
              :label="item.version"
              :value="item.id">
              <span style="float: left">{{ item.version }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.uploadName }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="itemEditData.equipmentType == '2'" label="波段选择">
          <el-select v-model="itemEditData.bandType" placeholder="请选择波段" class="equipTypeSelect">
            <el-option
              v-for="item in bandTypeList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="围栏半径">
              <el-input-number v-model="itemEditData.radius" placeholder="请输入围栏半径"></el-input-number>
              <!-- <el-input v-model="itemEditData.radius" placeholder="请输入围栏半径"></el-input> -->
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="围栏位置">
              <div class="equipmentPosition">
                <el-input-number v-model="itemEditData.latitude" placeholder="请输入纬度"></el-input-number>
                <el-input-number v-model="itemEditData.longitude" placeholder="请输入经度"></el-input-number>
                <el-button size="small" @click="equipmentLocation(itemEditData)">修改位置</el-button>
              </div>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="设备位置（经度）">
              <el-input-number v-model="itemEditData.longitude" placeholder="请输入经度"></el-input-number>
            </el-form-item>
          </el-col> -->
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="省" prop="province">
              <el-select v-model="itemEditData.province" placeholder="请选择省" @change="provinceHandleChange">
                <el-option
                  v-for="item in provinceList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="市" prop="city">
              <el-select v-model="itemEditData.city" placeholder="请选择市" @change="cityHandleChange">
                <el-option
                  v-for="item in cityList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="区" prop="area">
              <el-select v-model="itemEditData.area" placeholder="请选择区" @change="areaHandleChange">
                <el-option
                  v-for="item in areaList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="可见光积分(ms)">
              <el-input-number v-model="itemEditData.visible_light_integral" placeholder="请输入可见光积分"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="补光灯电压(V)">
              <el-input-number v-model="itemEditData.fill_lamp_voltage" placeholder="请输入补光灯电压" :step="1" :min="0"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="短波积分(ms)">
              <el-input-number v-model="itemEditData.shot_wave_integral" placeholder="请输入短波积分"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="设置增益(倍)">
              <el-input-number v-model="itemEditData.data_value_gain" placeholder="请输入设置增益"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="采集密度(次)">
              <el-input-number v-model="itemEditData.acquisition_density" placeholder="请输入采集密度"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设置偏压(mv)">
              <el-input-number v-model="itemEditData.power_supply_bias" placeholder="请输入设置偏压"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row> -->
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="参数a">
              <el-input-number v-model="itemEditData.parama" placeholder="请输入参数a" :disabled="itemEditData.id !== ''"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="参数b">
              <el-input-number v-model="itemEditData.paramb" placeholder="请输入参数b" :disabled="itemEditData.id !== ''"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="参数c">
              <el-input-number v-model="itemEditData.paramc" placeholder="请输入参数c" :disabled="itemEditData.id !== ''"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="itemEditData.equipmentType == '2'" :gutter="20">
          <el-col :span="8">
            <el-form-item label="短波参数a">
              <el-input-number v-model="itemEditData.shortParamA" placeholder="请输入短波参数a"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="短波参数b">
              <el-input-number v-model="itemEditData.shortParamB" placeholder="请输入短波参数b"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="短波参数c">
              <el-input-number v-model="itemEditData.shortParamC" placeholder="请输入短波参数c"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注">
          <el-input v-model="itemEditData.remark" placeholder="请输入备注"></el-input>
        </el-form-item>
      </el-form>
      <div class="dialogFooter">
        <el-button size="mini" @click="editDialogClose()">取消</el-button>
        <el-button
          type="primary"
          size="mini"
          @click="editDialogSubmit()"
        >保存</el-button>
      </div>
    </el-dialog>
    <!-- tableChangeDialogFlag -->
    <el-dialog
      v-if="equipmentInfoDialogFlag"
      title="设备详情"
      :visible.sync="equipmentInfoDialogFlag"
      width="80%"
      modal
      center
      class="equipmentInfo_dialog"
      :close-on-press-escape="false">
      <div class="equipmentInfo_bg">
        <el-form ref="equipmentInfo_form" :model="equipmentInfo" label-width="130px">
          <div class="equipmentInfo_title">设备基本信息</div>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="设备序列号">
                <span class="equipmentInfo_text">{{equipmentInfo.sernumber ? equipmentInfo.sernumber : '-'}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="主板编号">
                <span class="equipmentInfo_text">{{equipmentInfo.snId ? equipmentInfo.snId : '-'}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="用户设备名称">
                <span class="equipmentInfo_text">{{equipmentInfo.equipmentName ? equipmentInfo.equipmentName : '-'}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="设备名称">
                <span class="equipmentInfo_text">{{equipmentInfo.alias ? equipmentInfo.alias : '-'}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="设备类型">
                <span v-if="equipmentInfo.equipmentType == '1'" class="equipmentInfo_text">浮标式设备</span>
                <span v-else-if="equipmentInfo.equipmentType == '2'" class="equipmentInfo_text">便携式设备</span>
                <span v-else-if="equipmentInfo.equipmentType == '3'" class="equipmentInfo_text">岸基式设备</span>
                <span v-else-if="equipmentInfo.equipmentType == '4'" class="equipmentInfo_text">管道式设备</span>
                <span v-else-if="equipmentInfo.equipmentType == '5'" class="equipmentInfo_text">潜入式设备</span>
                <span v-else class="equipmentInfo_text">-</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="设备型号">
                <span class="equipmentInfo_text">{{equipmentInfo.equipmentModelName ? equipmentInfo.equipmentModelName : '-'}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="通讯模块编号">
                <span class="equipmentInfo_text">{{equipmentInfo.communicationCode ? equipmentInfo.communicationCode : '-'}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="通讯模块型号">
                <span class="equipmentInfo_text">{{equipmentInfo.model ? equipmentInfo.model : '-'}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="设备版本">
                <span class="equipmentInfo_text">{{equipmentInfo.version ? equipmentInfo.version : '-'}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="sim卡号">
                <span class="equipmentInfo_text">{{equipmentInfo.iccid ? equipmentInfo.iccid : '-'}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="光栅编号">
                <span class="equipmentInfo_text">{{equipmentInfo.rasterNumber ? equipmentInfo.rasterNumber : '-'}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="波段(nm)">
                <span v-if="equipmentInfo.bandType == '02'" class="equipmentInfo_text">1000-1700</span>
                <span v-else-if="equipmentInfo.bandType == '03'" class="equipmentInfo_text">400-1700</span>
                <span v-else-if="equipmentInfo.bandType == '04'" class="equipmentInfo_text">200-1000</span>
                <span v-else class="equipmentInfo_text">400-1000</span>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="equipmentInfo_title">设备参数信息</div>
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="可见光积分">
                <span class="equipmentInfo_text">{{equipmentInfo.visibleLightIntegral ? equipmentInfo.visibleLightIntegral : '0'}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="补光灯电压">
                <span class="equipmentInfo_text">{{equipmentInfo.fillLampVoltage ? equipmentInfo.fillLampVoltage : '0'}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="短波积分">
                <span class="equipmentInfo_text">{{equipmentInfo.shotWaveIntegral ? equipmentInfo.shotWaveIntegral : '0'}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="增益">
                <span class="equipmentInfo_text">{{equipmentInfo.dataValueGain ? equipmentInfo.dataValueGain : '0'}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="偏压">
                <span class="equipmentInfo_text">{{equipmentInfo.powerSupplyBais ? equipmentInfo.powerSupplyBais : '0'}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="参数a">
                <span class="equipmentInfo_text">{{equipmentInfo.parama}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="参数b">
                <span class="equipmentInfo_text">{{equipmentInfo.paramb}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="参数c">
                <span class="equipmentInfo_text">{{equipmentInfo.paramc}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="短波参数a">
                <span class="equipmentInfo_text">{{equipmentInfo.shortParamA}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="短波参数b">
                <span class="equipmentInfo_text">{{equipmentInfo.shortParamB}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="短波参数c">
                <span class="equipmentInfo_text">{{equipmentInfo.shortParamC}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="equipmentInfo_title">设备其他信息</div>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="设备所在地">
                <span class="equipmentInfo_text">{{equipmentInfo.addr ? equipmentInfo.addr : '-'}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="设备围栏">
                <span class="equipmentInfo_text">{{equipmentInfo.longitude + ',' + equipmentInfo.latitude + ' 半径 ' + equipmentInfo.radius}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="算法">
                <span class="equipmentInfo_text">{{equipmentInfo.algorithmName ? equipmentInfo.algorithmName : '-'}}</span>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户">
                <span class="equipmentInfo_text">{{equipmentInfo.customerName ? equipmentInfo.customerName : '-'}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="备注">
                <span class="equipmentInfo_text">{{equipmentInfo.remark ? equipmentInfo.remark : '-'}}</span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-dialog>
    <el-dialog
      v-if="alertPositionFlag"
      title="设备围栏"
      :visible.sync="alertPositionFlag"
      width="60%"
      modal
      :show-close="false"
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div class="alertPositionDialog_bg">
        <div class="alertPositionDialog_header">
          <el-select v-model="addrSearchVal"
            filterable
            remote
            clearable
            reserve-keyword
            placeholder="请搜索地点"
            @change="addrSelectListener"
            :remote-method="addrChangeListener"
            class="alertPositionDialog_select">
            <el-option
              v-for="item in addrSelect"
              :key="item.district + item.name"
              :label="item.name"
              :value="item.district + item.name">
              <span style="float: left">{{ item.name }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.district }}</span>
            </el-option>
          </el-select>
          <div class="alertPositionDialog_selfPosition">
            <div class="alertPositionDialog_selfPositionBtn" @click="toSelfPosition()"></div>
          </div>
        </div>
        <div class="alertPositionDialog_content">
          <div id="equPositionMap" class="alertPositionDialog_map" tabindex="0"></div>
        </div>
      </div>
      <div class="dialogFooter">
        <el-button size="mini" @click="closeProPositionDialog()">取消</el-button>
        <el-button
          type="primary"
          size="mini"
          @click="savealertPosition()"
        >保存</el-button>
      </div>
    </el-dialog>
    <el-dialog
      v-if="equParamsSettingFlag"
      title="设备指标配置"
      :visible.sync="equParamsSettingFlag"
      width="60%"
      modal
      :show-close="false"
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div class="equParamsSetting_bg">
        <div class="equParamsSetting_paramsTitle">
          <div class="equParamsSetting_paramsItemTitle">指标名称</div>
          <div class="equParamsSetting_paramsItemTitle">指标下限</div>
          <div class="equParamsSetting_paramsItemTitle">指标上限</div>
          <div class="equParamsSetting_paramsItemTitle">小数位数</div>
          <div class="equParamsSetting_paramsItemTitle">排序</div>
        </div>
        <div class="equParamsSetting_paramsBg">
          <div v-for="(item,index) in equParamsList" :key="item.paramKey" class="equParamsSetting_params">
            <div class="equParamsSetting_paramsItem">
              <div class="equParamsSettingItem_name" :style="item.paramtype == '1' ? 'color:orange' : ''">{{item.paramname}}</div>
              <i class="el-icon-refresh-left equParamsSettingItem_backIcon" @click="doParamRefresh(index)"></i>
            </div>
            <div class="equParamsSetting_paramsItem">
              <div class="equParamsSettingItem_up">
                <el-input-number v-model="item.paramdown" :min="0" size="small" placeholder="请输入指标下限" @change="onInputChange(index,'paramdown')"></el-input-number>
              </div>
            </div>
            <div class="equParamsSetting_paramsItem">
              <div class="equParamsSettingItem_down">
                <el-input-number v-model="item.paramup" :min="0" size="small" placeholder="请输入指标上限" @change="onInputChange(index,'paramup')"></el-input-number>
              </div>
            </div>
            <div class="equParamsSetting_paramsItem">
              <div class="equParamsSettingItem_decimals">
                <el-input-number v-model="item.reserved" :min="0" :max="10" size="small" placeholder="请输入小数位数" @change="onInputChange(index,'reserved')"></el-input-number>
              </div>
            </div>
            <div class="equParamsSetting_paramsItem">
              <div class="equParamsSettingItem_sort">
                <el-input-number v-model="item.sort" :min="0" size="small" placeholder="请输入排序" @change="onInputChange(index,'sort')"></el-input-number>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="dialogFooter">
        <el-button size="mini" @click="closeEquParamsSettingDialog()">取消</el-button>
        <el-button
          type="primary"
          size="mini"
          @click="saveEquParamsSetting()"
        >保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>


<script>
import MetaPageTable from '../components/MetaPageTable'
import MetaSearchForm from '../components/MetaSearchForm'
import deepClone from '../utils/deepClone'

import { validateLetterNumber} from '../utils/validate'
export default {
  name: 'equipmentManagement',
  components: {
    MetaPageTable,
    MetaSearchForm
  },
  data () {
    var checkSernumber = (rule, value, callback) => {
      if(!value){
        return callback(new Error('请输入设备序列号'))
      }else{
        if (value.trim() === '') {
          return callback(new Error('请输入设备序列号'))
        }else{
          return callback()
        }
      }
    }
    var checkName = (rule, value, callback) => {
      if (value.trim() === '') {
        return callback(new Error('请输入用户设备名称'))
      }else{
        return callback()
      }
    }
    var checkAlias = (rule, value, callback) => {
      if(!value){
        return callback(new Error('请输入设备名称'))
      }else{
        if (value.trim() === '') {
          return callback(new Error('请输入设备名称'))
        }else{
          return callback()
        }
      }
    }
    let validateSnid = (rule, value, callback) => {
      let val = value.trim()
      if (val === '') {
        callback(new Error('请输入主板编号'));
      } else {
        if (!validateLetterNumber(val)) {
          callback(new Error('请输入英文或数字'));
        }
        callback();
      }
    }
    return {
      alertPositionFlag: false,
      addrSearchVal: '',
      addrSelect: [],
      equPositionMap: null,
      equipmentPosition: {},
      tableChangeDialogFlag: false,
      equipmentInfoDialogFlag: false,//设备详情
      equipmentInfo: {},
      searchData: {
        sernumber: '',
        equipmentname: '',
        // ontype: '',
        snid: '',
        alias: '',
        customerId: ''
      },
      equTableData: {},
      searchDataForTable: {},
      provinceList: [],
      cityList: [],
      areaList: [],
      displayItem: [
        {
          label: '设备序列号',
          prop: 'sernumber'
        },
        {
          label: '用户设备名称',
          prop: 'equipmentName'
        },
        {
          label: '设备名称',
          prop: 'alias'
        },
        {
          label: '主板编号',
          prop: 'snId'
        },
        {
          label: '设备类型',
          prop: 'equipmentType',
          type: "if",
          format: {
            '1': "浮标式设备",
            '2': "便携式设备",
            '3': "岸基式设备",
            '4': "管道式设备",
            '5': "潜入式设备",
          }
        },
        {
          label: '设备版本',
          prop: 'version'
        },
        {
          label: '通讯模块编号',
          prop: 'communicationCode'
        },
        {
          label: '通讯模块型号',
          prop: 'model'
        },
        {
          label: '光栅编号',
          prop: 'rasterNumber'
        },
        {
          label: 'sim卡号',
          prop: 'iccid'
        },
        {
          label: '设备型号',
          prop: 'equipmentModelName'
        },
        {
          label: '客户',
          prop: 'customerName'
        },
        // {
        //   label: '波段(nm)',
        //   prop: 'bandType',
        //   type: 'if',
        //   format: { // 400-1000 -> 01 , 1000-1700 -> 02 , 400-1700 -> 03 , 200-1000 -> 10
        //     '01': "400-1000",
        //     '02': "1000-1700",
        //     '03': "400-1700",
        //     '10': "200-1000"
        //   }
        // },
        // {
        //   label: '设备位置（纬度）',
        //   prop: 'latitude'
        // },
        // {
        //   label: '设备位置（经度）',
        //   prop: 'longitude'
        // },
        // {
        //   label: '围栏半径',
        //   prop: 'radius'
        // },
        {
          label: '设备所在地',
          prop: 'addr',
        },
        {
          label: '算法名称',
          prop: 'algorithmName'
        },
        {
          label: '定标系数',
          prop: 'dbxsType',
          type: 'if',
          format: {
            '0': '白板系数',
            '1': '灰板系数',
            '2': '无系数'
          }
        },
        {
          label: '暗电流参与计算',
          type: 'if',
          prop: 'adlType',
          format: {
            '1': '是',
            'else': ''
          }
        },
        // {
        //   label: '状态',
        //   prop: 'ontype',
        //   type: "if",
        //   format: {
        //     '1': "在线",
        //     '2': "调试",
        //     '3': "维修",
        //     '4': "报警",
        //   },
        //   color: {
        //     '1': '#00E436',
        //     '2': '#00A8FF',
        //     '3': '#FFA11A',
        //     '4': '#FF501A'
        //   }
        // },
        // {
        //   label: '可见光积分',
        //   prop: 'visible_light_integral',
        // },
        // {
        //   label: '补光灯电压',
        //   prop: 'fill_lamp_voltage',
        // },
        // {
        //   label: '短波积分',
        //   prop: 'shot_wave_integral',
        // },
        // {
        //   label: '设置增益',
        //   prop: 'data_value_gain',
        // },
        // // {
        // //   label: '采集密度',
        // //   prop: 'acquisition_density',
        // // },
        // {
        //   label: '设置偏压',
        //   prop: 'power_supply_bias',
        // },
        // {
        //   label: '参数a',
        //   prop: 'parama',
        // },
        // {
        //   label: '参数b',
        //   prop: 'paramb',
        // },
        // {
        //   label: '参数c',
        //   prop: 'paramc',
        // },
        {
          label: '备注',
          prop: 'remark',
        },
      ],
      lineBtnGroup: [
        {
          id: 'edit',
          title: '编辑',
        },
        {
          id: 'info',
          title: '详情'
        },
        {
          id: 'paramSet',
          title: '指标配置'
        },
        {
          id: 'delete',
          title: '删除'
        }
      ],
      btnGroup: [{
        id: 'new',
        title: '新建'
      }],
      itemEditData: {
        id: '',
        aid: '',
        aName:'',
        equipmentname: '',
        alias: '',
        equipmentType: '',
        snid: '',
        model: '',
        latitude: '',
        longitude: '',
        radius: '',
        province: '',
        city: '',
        area: '',
        customerName:'',
        area_code: '',
        version: '',
        parama: 0,
        paramb: 0,
        paramc: 0,
        remark: '',
        sernumber: '',
        shortParamA: 0,
        shortParamB: 0,
        shortParamC: 0,
        bandType: '01',
        emid: '', //设备型号
        communicationCode: '', //通讯模块编号
        rasterNumber: '', //光栅编号
        customerId: '',//客户
        dbxsType: '0',
        adlType: '0'
      },
      editRules: {
        sernumber: [
          { required: true, validator: checkSernumber, trigger: 'blur' },
          { max: 50, message: '长度少于50个字', trigger: 'blur' }
        ],
        equipmentname: [
          { required: true, validator: checkName, trigger: 'blur' },
          { max: 30, message: '长度少于30个字', trigger: 'blur' }
        ],
        alias: [
          { required: true, validator: checkAlias, trigger: 'blur' },
          { max: 30, message: '长度少于30个字', trigger: 'blur' }
        ],
        snid: [
          { required: true, validator: validateSnid, trigger: 'blur' },
          { max: 20, message: '长度少于20个字', trigger: 'blur' }
        ],
        equipmentType: [
          { required: true, message: '请选择设备类型', trigger: 'change' },
        ],
        province: [
          { required: true, message: '请选择省', trigger: 'change' },
        ],
        city: [
          { required: true, message: '请选择市', trigger: 'change' },
        ],
        area: [
          { required: true, message: '请选择区', trigger: 'change' },
        ],
      },
      // 400-1000 -> 01 , 1000-1700 -> 02 , 400-1700 -> 03 , 200-1000 -> 10
      bandTypeList: [{
        id: '01',
        name: '400 - 1000nm'
      },{
        id: '02',
        name: '1000 - 1700nm'
      },{
        id: '03',
        name: '400 - 1700nm'
      },{
        id: '10',
        name: '200 - 1000nm'
      }],
      // equTypeList: [{
      //   value: 1,
      //   label: '在线'
      // },{
      //   value: 2,
      //   label: '调试'
      // },{
      //   value: 3,
      //   label: '维修'
      // },{
      //   value: 4,
      //   label: '报警'
      // }],
      algorithmList: [],
      customerList: [], //客户
      equipmentModelList: [], //设备型号
      equParamEId: '',
      equParamsSettingFlag: false,
      equParamsList: [],
      equParamsOriginalList: [],
      page:1
    }
  },
  created() {

  },
  mounted() {

    this.initProvinceList()
    //获取客户列表
    this.getCustomerList()
    //获取设备型号列表
    this.getEquipmentModelList()
    this.initAlgorithmList()
    this.page = 1
    this.initTableData(this.page,true)
  },
  methods: {
    initTableData(page,reflash) {
      let params = {}
      params = this.searchDataForTable
      params.page = page
      params.limit = 10
      this.$fetch({
        url: process.env.PROGOO_GATE_WATER + 'admin/equipmentListMap',
        method: "post",
        data: params
      }).then(res => {
        if (res.data.code === 200) {
          this.equTableData = {};
          this.equTableData.page = page;
          this.equTableData.totalElements = res.data.result.totalElements;
          this.equTableData.content = res.data.result.content;
          // if(this.equTableData.content) {
          //   for(let i in this.equTableData.content) {
          //     let addr = ''
          //     for(let j in this.equTableData.content[i].areaCodes) {
          //       addr += this.equTableData.content[i].areaCodes[j].name + ' '
          //     }
          //     if(this.equTableData.content[i].addr && this.equTableData.content[i].addr !== '') {
          //       addr += this.equTableData.content[i].addr + ' '
          //     }
          //     this.equTableData.content[i].addr = addr
          //     console.log(addr)

          //     for(let j in this.algorithmList) {
          //       if(this.algorithmList[j].id === this.equTableData.content[i].aid) {
          //         this.equTableData.content[i].aName = this.algorithmList[j].version
          //         break
          //       }
          //     }
          //     if(this.equTableData.content[i].equipmentRecord) {
          //       this.equTableData.content[i].visible_light_integral = this.equTableData.content[i].equipmentRecord.visible_light_integral
          //       this.equTableData.content[i].fill_lamp_voltage = this.equTableData.content[i].equipmentRecord.fill_lamp_voltage
          //       this.equTableData.content[i].shot_wave_integral = this.equTableData.content[i].equipmentRecord.shot_wave_integral
          //       this.equTableData.content[i].data_value_gain = this.equTableData.content[i].equipmentRecord.data_value_gain
          //       this.equTableData.content[i].power_supply_bias = this.equTableData.content[i].equipmentRecord.power_supply_bias
          //     }
          //   }
          //   console.log(this.equTableData.content)
          // }
          if(this.equTableData.content){
            for(let i in this.equTableData.content){
              let addr = ''
              addr += this.equTableData.content[i].provinceName+ ' ' +this.equTableData.content[i].cityName+ ' ' +this.equTableData.content[i].areaName
              this.equTableData.content[i].addr = addr

            }
          }
          this.$nextTick(() => {
            this.$refs.equipmentManagementTable.formDataInit(reflash,this.equTableData)
          })
        }else {
          this.$notify.error({
            title: '错误',
            message: res.data.message
          });
        }
      })
    },
    getCustomerList() {
      this.$fetch({
        url: process.env.PROGOO_GATE_WATER + 'admin/customer',
        method: "post",
        data: {
          page: 1,
          limit: 99999999
        }
      }).then(res => {
        if (res.data.code === 200) {
          this.customerList = res.data.result.content

        }else {
          this.$notify.error({
            title: '错误',
            message: res.data.message
          });
        }
      })
    },
    initAlgorithmList() {
      this.$fetch({
        url: process.env.PROGOO_GATE_WATER + 'admin/algorithm/algorithmList',
        method: "get"

      }).then(res => {
        if (res.data.code === 200) {
          this.algorithmList = res.data.result

        //   if(callback && typeof(callback) === 'function') {
        //     callback()
        //   }
        // }else {
        //   this.$notify.error({
        //     title: '错误',
        //     message: res.data.message
        //   });
        }
      })
    },
    initProvinceList() {
      this.initPCAList(0, 'province')
    },
    initPCAList(id, type, callback) {
      if(id === '') {
        return
      }
      let data = {}
      if(type === 'province') {
        data.level = 1
      }else if (type === 'city') {
        data.level = 2
      }else if (type === 'area') {
        data.level = 3
      }
      data.parentid = id
      this.$fetch({
        url: process.env.PROGOO_GATE_WATER + "admin/company/area",
        method: "post",
        data: data
      }).then(res => {
        if(type === 'province') {
          this.provinceList = res.data.result
        }else if (type === 'city') {
          this.cityList = res.data.result
        }else if (type === 'area') {
          this.areaList = res.data.result
        }
        if(callback && typeof(callback) === 'function') {
          callback()
        }
      })
    },
    provinceHandleChange(id) {
      this.cityList = []
      this.areaList = []
      this.itemEditData.city = ''
      this.itemEditData.area = ''
      this.initPCAList(id, 'city')
    },
    cityHandleChange(id) {
      this.areaList = []
      this.itemEditData.area = ''
      this.initPCAList(id, 'area')
    },
    areaHandleChange(id) {
      for(let i in this.areaList) {
        if(this.areaList[i].id === id) {
          this.itemEditData.area_code = this.areaList[i].adcode
          break
        }
      }
    },
    tableInlineBtnClick(item) {
      if (item.button === 'edit') {
        this.itemEditData = {
          id: item.rows.equipmentId,
          equipmentname: item.rows.equipmentName,
          aid:item.rows.aid,
          alias: item.rows.alias,
          equipmentType: item.rows.equipmentType ? parseInt(item.rows.equipmentType) : '',
          snid: item.rows.snId,
          model: item.rows.model,
          latitude: item.rows.latitude,
          longitude: item.rows.longitude,
          radius: item.rows.radius,
          province: item.rows.province ? parseInt(item.rows.province) : '',
          city: item.rows.city ? parseInt(item.rows.city) : '',
          area: item.rows.areaId ? parseInt(item.rows.areaId) : '',
          area_code: item.rows.area_code,
          aName:item.rows.algorithmName,
          // visible_light_integral: item.rows.visible_light_integral,
          // fill_lamp_voltage: item.rows.fill_lamp_voltage,
          // shot_wave_integral: item.rows.shot_wave_integral,
          // data_value_gain: item.rows.data_value_gain,
          // acquisition_density: item.rows.acquisition_density,
          // power_supply_bias: item.rows.power_supply_bias,
          version: item.rows.version,
          parama: item.rows.parama ? item.rows.parama : 0,
          paramb: item.rows.paramb ? item.rows.paramb : 0,
          paramc: item.rows.paramc ? item.rows.paramc : 0,
          remark: item.rows.remark,
          shortParamA: item.rows.shortParamA ? item.rows.shortParamA : 0,
          shortParamB: item.rows.shortParamB ? item.rows.shortParamB : 0,
          shortParamC: item.rows.shortParamC ? item.rows.shortParamC : 0,
          sernumber: item.rows.sernumber,
          bandType: item.rows.bandType ? item.rows.bandType : '01',
          emid: item.rows.emid ? item.rows.emid : '',
          customerId: item.rows.customerId ? item.rows.customerId : '',
          customerName:item.rows.customerName?item.rows.customerName:'',
          communicationCode: item.rows.communicationCode ? item.rows.communicationCode : '',
          rasterNumber: item.rows.rasterNumber ? item.rows.rasterNumber : '',
          dbxsType: item.rows.dbxsType ? item.rows.dbxsType : '0',
          adlType: item.rows.adlType ? item.rows.adlType : '0',
        }
        this.cityList = []
        this.areaList = []
        this.initPCAList(this.itemEditData.province, 'city', () => {
          this.initPCAList(this.itemEditData.city, 'area')
        })
        this.tableChangeDialogFlag = true
      }else if (item.button === 'delete') {
        this.$confirm('确认删除此设备?', '设备删除', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$fetch({
            url: process.env.PROGOO_GATE_WATER + "admin/equipment/delete",
            method: "post",
            data: {
              id: item.rows.equipmentId
            }
          }).then(res => {
            if (res.data.code === 200) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
              this.initTableData(this.page,false)
            }else {
              this.$notify.error({
                title: '错误',
                message: res.data.message
              });
            }
          })
        })
      }else if (item.button === 'info') {
        this.equipmentInfo = item.rows

        this.equipmentInfoDialogFlag = true
      }else if (item.button === 'paramSet') {

        //获取参数信息
        this.$fetch({
          url: process.env.PROGOO_GATE_WATER + "admin/equipment/paramList",
          method: "put",
          params: {
            eid: item.rows.equipmentId
          }
        }).then(res => {
          if (res.data.code === 200) {
            this.equParamEId = item.rows.equipmentId
            this.equParamsSettingFlag = true
            this.equParamsList = deepClone(res.data.result)
            this.equParamsOriginalList = deepClone(res.data.result)

          }else {
            this.$notify.error({
              title: '错误',
              message: res.data.message
            });
          }
        })
      }
    },
    tableBtnClick(item) {
      if (item.button === 'new') {
        this.itemEditData = {
          id: '',
          aid: '',
          equipmentname: '',//设备用户名称
          alias: '', //设备名称
          equipmentType: '', //设备类型
          snid: '',  //主板编号
          model: '', //通讯模块型号
          latitude: '',
          longitude: '',
          radius: '',
          province: '', //省
          city: '',  //市
          area: '',  //区
          area_code: '',
          version: '',  //设备版本
          parama: 0,  //参数a
          paramb: 0,  //参数b
          paramc: 0, //参数c
          shortParamA: 0,  //短波参数a
          shortParamB: 0,//短波参数b
          shortParamC: 0,   //短波参数c
          remark: "",    //备注
          sernumber: "",    //设备序列号
          bandType: '01',   //波段
          emid: '',   //设备型号
          customerId: '',  //客户id
          communicationCode: '',  //通讯模块编号
          customerName:'',   //客户名称
          rasterNumber: '',  //光栅编号
          dbxsType: '0',   //定标系数
          adlType: '0'  ,//暗电流参与计算
          aName:''

        }
        this.tableChangeDialogFlag = true
      }
    },
    pageChange(e){
      this.page = e
      this.initTableData(this.page, false)
    },
    tableSearch() {
      this.searchDataForTable = deepClone(this.searchData)
      this.page = 1
      this.initTableData(this.page,true)
    },
    editDialogSubmit() {
      this.$refs['equipmentEdit_form'].validate((valid) => {
        if (valid) {
          let params = {}
          if(this.itemEditData.id !== '') {
            params.id = this.itemEditData.id
          }
          params.equipmentname = this.itemEditData.equipmentname.trim()
          params.alias = this.itemEditData.alias.trim()
          params.snid = this.itemEditData.snid.trim()
          params.model = this.itemEditData.model
          params.equipment_type = this.itemEditData.equipmentType
          params.latitude = this.itemEditData.latitude
          params.longitude = this.itemEditData.longitude
          params.radius = this.itemEditData.radius
          params.province = this.itemEditData.province
          params.city = this.itemEditData.city
          params.areaid = this.itemEditData.area
          params.area_code = this.itemEditData.area_code
          params.version = this.itemEditData.version
          params.remark = this.itemEditData.remark
          params.sernumber = this.itemEditData.sernumber.trim()
          params.aid = this.itemEditData.aid
          // params.visible_light_integral = this.itemEditData.visible_light_integral != '' ? this.itemEditData.visible_light_integral : 0
          // params.fill_lamp_voltage = this.itemEditData.fill_lamp_voltage != '' ? this.itemEditData.fill_lamp_voltage : 0
          // params.shot_wave_integral = this.itemEditData.shot_wave_integral != '' ? this.itemEditData.shot_wave_integral : 0
          // params.data_value_gain = this.itemEditData.data_value_gain != '' ? this.itemEditData.data_value_gain : 0
          // params.acquisition_density = this.itemEditData.acquisition_density != '' ? this.itemEditData.acquisition_density : 0
          // params.power_supply_bias = this.itemEditData.power_supply_bias != '' ? this.itemEditData.power_supply_bias : 0
          params.parama = this.itemEditData.parama != '' ? this.itemEditData.parama : 0
          params.paramb = this.itemEditData.paramb != '' ? this.itemEditData.paramb : 0
          params.paramc = this.itemEditData.paramc != '' ? this.itemEditData.paramc : 0

          params.shortParamA = this.itemEditData.shortParamA != '' ? this.itemEditData.shortParamA : 0
          params.shortParamB = this.itemEditData.shortParamB != '' ? this.itemEditData.shortParamB : 0
          params.shortParamC = this.itemEditData.shortParamC != '' ? this.itemEditData.shortParamC : 0

          params.bandType = this.itemEditData.bandType != '' ? this.itemEditData.bandType : '01'
          params.emid = this.itemEditData.emid != '' ? this.itemEditData.emid : ''
          params.customerId = this.itemEditData.customerId != '' ? this.itemEditData.customerId : ''
          for(let i in this.customerList){
            this.itemEditData.customerName = this.customerList[i].customerName
            params.customerName =this.itemEditData.customerName !=''?this.itemEditData.customerName :''

          }
          params.communicationCode = this.itemEditData.communicationCode != '' ? this.itemEditData.communicationCode : ''
          params.rasterNumber = this.itemEditData.rasterNumber != '' ? this.itemEditData.rasterNumber : ''
          params.dbxsType = this.itemEditData.dbxsType != '' ? this.itemEditData.dbxsType : '0'
          params.adlType = this.itemEditData.adlType != '' ? this.itemEditData.adlType : '0'
          this.$fetch({
            url: process.env.PROGOO_GATE_WATER + "admin/equipment/edit",
            method: "post",
            data: params
          }).then(res => {
            if (res.data.code === 200) {
              this.$message({
              message: '保存成功',
              type: 'success'
            });
              this.editDialogClose()
              this.initTableData(this.page,false)
            }else {
              this.$notify.error({
                title: '错误',
                message: res.data.message
              });
            }
          })
        } else {
          return false;
        }
      });
    },
    editDialogClose() {
      this.itemEditData = {
        id: '',
        aid: '',
        equipmentname: '',
        alias: '',
        equipmentType: '',
        snid: '',
        model: '',
        latitude: '',
        longitude: '',
        radius: '',
        province: '',
        city: '',
        area: '',
        area_code: '',
        emid: '',
        customerId: '',
        communicationCode: '',
        rasterNumber: '',
        version: '',
        dbxsType: '0',
        adlType: '0',
        aName:''
      }
      this.tableChangeDialogFlag = false
    },
    aNameChange(e){
      this.itemEditData.aid = e

    },
    getEquipmentModelList() {
      this.$fetch({
        url: process.env.PROGOO_GATE_WATER + "admin/EquipmentModel",
        method: "post",
        data: {
          page: 1,
          limit: 99999999
        }
      }).then(res => {
        if (res.data.code === 200) {
          this.equipmentModelList = res.data.result.content
        }else {
          this.$notify.error({
            title: '错误',
            message: res.data.message
          });
        }
      })

    },
    addrChangeListener(val) {
      let that = this
      AMap.plugin('AMap.Autocomplete', function(){
        // 实例化Autocomplete
        var autoOptions = {
          //city 限定城市，默认全国
          city: '全国'
        }
        var autoComplete= new AMap.Autocomplete(autoOptions);
        autoComplete.search(val, function(status, result) {
          // 搜索成功时，result即是对应的匹配数据
          that.addrSelect = result.tips
        })
      })
    },
    addrSelectListener() {
      if(this.addrSearchVal === '') {
        this.addrSelect = []
      }else {
        for(let i in this.addrSelect) {
          let addr = this.addrSelect[i].district + this.addrSelect[i].name
          if(addr === this.addrSearchVal) {
            let that = this
            let center = new AMap.LngLat(this.addrSelect[i].location.lng, this.addrSelect[i].location.lat)
            that.equPositionMap.setCenter(center)
            that.equPositionMap.clearMap()
            that.equipmentPosition = {}
            var marker = new AMap.Marker({
              position: new AMap.LngLat(this.addrSelect[i].location.lng, this.addrSelect[i].location.lat),
            })
            that.equipmentPosition.lng = this.addrSelect[i].location.lng
            that.equipmentPosition.lat = this.addrSelect[i].location.lat
            that.equPositionMap.add(marker);
            break
          }
        }
      }
    },
    toSelfPosition() {
      if(Object.keys(this.equipmentPosition).length > 0) {
        let center = new AMap.LngLat(this.equipmentPosition.lng, this.equipmentPosition.lat)
        this.equPositionMap.setCenter(center)
      }
    },
    savealertPosition() {
      if(Object.keys(this.equipmentPosition).length > 0) {
        //LDC 保存经纬度
        this.itemEditData.latitude = this.equipmentPosition.lat
        this.itemEditData.longitude = this.equipmentPosition.lng
        this.closeProPositionDialog()
      }else {
        this.$notify.warning({
          title: '提示',
          message: '请选择设备位置'
        });
      }
    },
    closeProPositionDialog() {
      this.equipmentPosition = {}
      this.equPositionMap.clearMap()
      this.addrSearchVal = ""
      this.alertPositionFlag = false
    },
    equipmentLocation(item) {
      // LDC 设备经纬度
      this.alertPositionFlag = true

      this.$nextTick(() => {

        this.equipmentPosition = {}
        let mapCenter = []
        if(item.longitude && item.longitude !== '' && item.longitude !== 0) {
          this.equipmentPosition.lng = item.longitude
          this.equipmentPosition.lat = item.latitude
          mapCenter = [this.equipmentPosition.lng,this.equipmentPosition.lat]
        }else {
          mapCenter = [117.072723,39.098484]
        }

        this.equPositionMap = new AMap.Map('equPositionMap', {
          zoom: 15,
          resizeEnable: true,
          center: mapCenter,
          pitch: 0,
          viewMode: '3D'
        })
        // 绑定事件
        this.equPositionMap.on('click', this.clickMapHandler);

        if(Object.keys(this.equipmentPosition).length > 0) {
          var marker = new AMap.Marker({
            position: mapCenter,
          })
          this.equPositionMap.add(marker);
        }
      })
    },
    clickMapHandler(e) {
      this.equPositionMap.clearMap()
      this.equipmentPosition = {}
      var marker = new AMap.Marker({
        position: new AMap.LngLat(e.lnglat.getLng(), e.lnglat.getLat()),
      })
      this.equipmentPosition.lng = e.lnglat.getLng()
      this.equipmentPosition.lat = e.lnglat.getLat()
      this.equPositionMap.add(marker);
    },
    closeEquParamsSettingDialog() {
      this.equParamsList = []
      this.equParamsOriginalList = []
      this.equParamEId = ''
      this.equParamsSettingFlag = false
    },
    saveEquParamsSetting() {
      this.$fetch({
        url: process.env.PROGOO_GATE_WATER + "admin/equipment/param?eid=" + this.equParamEId,
        method: "put",
        data: this.equParamsList
      }).then(res => {
        if (res.data.code === 200) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.closeEquParamsSettingDialog()
        }else {
          this.$notify.error({
            title: '错误',
            message: res.data.message
          });
        }
      })
    },
    doParamRefresh(index) {
      this.$confirm('是否确认重置当前参数的所有值', '重置当前参数', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let changeList = deepClone(this.equParamsList)
        changeList[index] = deepClone(this.equParamsOriginalList[index])
        this.equParamsList = []
        this.equParamsList = deepClone(changeList)
      })
    },
    onInputChange(index, key) {
      if(!this.equParamsList[index][key] && typeof this.equParamsList[index][key] != 'number') {
        this.equParamsList[index][key] = 0
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less">
.equipmentManagement{
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 15px;
  overflow-y: scroll;
  .equipmentManagement_formItem {
    float: left;
  }
  .equipmentManagement_table {
    width: 100%;
    overflow-y: unset;
  }
  .equipTypeSelect {
    width: 100%;
  }
}
.alertPositionDialog_bg {
  height: 600px;
  .alertPositionDialog_header {
    width: 100%;
    height: 60px;
    float: left;
    display: flex;
    .alertPositionDialog_select {
      flex: 1;
    }
    .alertPositionDialog_selfPosition {
      width: 50px;
      padding-left: 10px;
      box-sizing: border-box;
      .alertPositionDialog_selfPositionBtn {
        width: 40px;
        height: 40px;
        background-image: url('~@/assets/images/location.png');
        background-size: 100% 100%;
        cursor: pointer;
      }
      .alertPositionDialog_selfPositionBtn:active {
        background-image: url('~@/assets/images/location_o.png');
      }
    }
  }
  .alertPositionDialog_content {
    width: 100%;
    height: 500px;
    float: left;
    .alertPositionDialog_map {
      width: 100%;
      height: 100%;
      float: left;
    }
  }
}
.equipmentInfo_dialog {
  width: 100%;
  .equipmentInfo_bg {
    max-height: 600px;
    width: 100%;
    overflow: hidden;
    overflow-y: scroll;
    .equipmentInfo_title {
      width: 100%;
      height: 38px;
      font-size: 16px;
      box-sizing: border-box;
      padding: 0 10px;
    }
    .el-form-item__label {
      color: #333;
    }
    .equipmentInfo_text {
      color: #888;
    }
  }
}
.equipmentInfo_dialog .el-dialog__body {
  padding-right: 0px!important;
}
.equParamsSetting_bg {
  width: 100%;
  .equParamsSetting_paramsBg {
    width: 100%;
    height: 500px;
    overflow-y: scroll;
    .equParamsSetting_params {
      width: 100%;
      display: flex;
      .equParamsSetting_paramsItem {
        width: 100%;
        flex: 1;
        margin-bottom: 10px;
        box-sizing: border-box;
        padding: 0 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        .equParamsSettingItem_backIcon {
          font-size: 18px;
          margin-left: 8px;
          color: #114ca6;
          cursor: pointer;
        }
      }
    }
  }
  .equParamsSetting_paramsTitle {
    width: 100%;
    display: flex;
    box-sizing: border-box;
    padding-right: 15px;
    .equParamsSetting_paramsItemTitle {
      width: 100%;
      flex: 1;
      margin-bottom: 10px;
      box-sizing: border-box;
      padding: 0 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      height: 45px;
      color: black;
    }
  }
}
.dialogFooter {
  display: flex;
  justify-content: center;
  margin-top: 0.5rem;
}
</style>
